<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>玉灵 QQ:7031633 Email:webrx@126.com</title>
    <meta name="keywords" content="关键字">
    <meta name="description" content="简介">
</head>

<body>
<h3>客户端时钟：</h3>
<p class="ct"></p>
<script>
    setInterval(()=>{
        let d = new Date();
        let yyyy = d.getFullYear()
        let mm = (d.getMonth()+1).toString().padStart(2,0)
        let dd = d.getDate().toString().padStart(2,0)
        let hh = d.getHours().toString().padStart(2,0)
        let mi = d.getMinutes().toString().padStart(2,0)
        let ss = d.getSeconds().toString().padStart(2,0)
        let ts = `${yyyy}-${mm}-${dd} ${hh}:${mi}:${ss}`
        document.querySelector(".ct").innerHTML = ts
    },1000)
</script>


<h3>服务器时钟：</h3>
<p class="t"></p>
<hr>
<p class="db">

</p>
<script>
    //ajax get
    //建立ajax 对象
    let xmlhttp = new XMLHttpRequest();

    //为ajax对象添加事件
    xmlhttp.onreadystatechange = function(){
        if(xmlhttp.status==200 && xmlhttp.readyState==4){
            //console.log(xmlhttp.responseText)
            document.querySelector('.t').innerHTML = xmlhttp.responseText
        }
    }

    //http://localhost/user 发一个get 请求
    xmlhttp.open('get','/timers')

    setInterval(()=>{
        xmlhttp.open('get','/timers')
        xmlhttp.send()
    },1000)
    xmlhttp.send()


    //ajax post
    let aa = new XMLHttpRequest()
    aa.onreadystatechange = function(){
        if(aa.status===200 && aa.readyState===4){

            let dbs = JSON.parse(aa.responseText)
            for(let s of dbs){
                document.querySelector(".db").innerHTML+=`<h3>${s}</h3>`
            }
        }
    }
    aa.open('post',"/save",true)
    aa.setRequestHeader("Content-type","application/x-www-form-urlencoded");
    //向服务器请求post 并提交两个值
    aa.send('id=66&name='+encodeURIComponent('李四七'))
</script>
</body>
</html>
